<template>
	<view>
		<view class="person-head">
			<image class="cu-avatar round xl" :src="userInfo.avatarUrl" mode="widthFix"></image>
			<view class="person-head-box">
				<view class="person-head-nickname" @tap="getUserProfile">
					{{userInfo.nickName ? userInfo.nickName : '点击登录'}}
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import BASE_URL from '../../../common/config.js'
	export default {
		data() {
			return {
				userInfo: {}
			}
		},
		mounted() {
			this.userInfo = wx.getStorageSync('userInfo')
			wx.getSetting({
			  success (res) {
			    console.log(res.authSetting)
			    // res.authSetting = {
			    //   "scope.userInfo": true,
			    //   "scope.userLocation": true
			    // }
			  }
			})
		},
		methods: {
			getUserProfile(e) {
				wx.login({
					success: (res) => {
						if (res.code) {
							wx.request({
								url: 'http://localhost:8082/app/sys/login',
								data: {
									code: res.code
								},
								header: {
									'content-type': 'application/json'
								},
								success: (data) => {
								},
								fail: (res) => {
									// console.log(res)
								}
							})
						} else {
							uni.showModal({
								title: "授权用户信息失败！",
								// 是否显示取消按钮，默认为 true
								showCancel: false
							})
						}
					},
					fail: (res) => {
						uni.showModal({
							title: "授权用户信息失败！",
							// 是否显示取消按钮，默认为 true
							showCancel: false
						})
					}
				})
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						// console.log(res)
						this.userInfo = res.userInfo
						// this.userInfo.openid = 1
						// console.log(this.userInfo)
						wx.setStorage({
							data: res.userInfo,
							key: 'userInfo'
						})
					},
					fail: (res) => {
						uni.showModal({
							title: "授权用户信息失败！",
							// 是否显示取消按钮，默认为 true
							showCancel: false
						})
					}
				})
			}
		}
	}
</script>

<style>
	.person-head {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 150px;
		padding-left: 20px;
		background: linear-gradient(to right, #365fff, #36bbff);
	}

	.person-head-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: flex-start;
		margin-left: 10px;
	}

	.person-head-nickname {
		font-size: 18px;
		font-weight: 500;
		color: #fff;
	}

	.person-head-username {
		font-size: 14px;
		font-weight: 500;
		color: #fff;
	}

	.person-list {
		line-height: 0;
	}

	.cu-list.card-menu {
		overflow: hidden;
		margin-right: 5px;
		margin-left: 5px;
		border-radius: 7px;
	}

	.cu-list.card-menu.margin-top-20 {
		margin-top: -20px;
	}

	.cu-list.menu>.cu-item .content>uni-view:first-child {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		/* -webkit-align-items: center; */
		/* align-items: center; */
		display: inline-block;
		margin-right: 5px;
		width: 1.6em;
		text-align: center;
	}
</style>
